import {
  FormProps,
  FormItemProps,
  AutoCompleteProps as _AutoCompleteProps,
  ButtonProps as _ButtonProps,
  CalendarProps as _CalendarProps,
  CascaderProps as _CascaderProps,
  CheckboxGroupProps as _CheckboxGroupProps,
  CheckboxProps as _CheckboxProps,
  ColProps as _ColProps,
  DatePickerProps as _DatePickerProps,
  InputNumberProps as _InputNumberProps,
  InputProps as _InputProps,
  RadioGroupProps as _RadioGroupProps,
  RateProps as _RateProps,
  RowProps as _RowProps,
  SelectProps as _SelectProps,
  SliderProps as _SliderProps,
  SwitchProps as _SwitchProps,
  TextAreaProps as _TextAreaProps,
  TimePickerProps as _TimePickerProps,
  TimeRangePickerProps as _TimeRangePickerProps,
  TransferProps as _TransferProps,
  TreeSelectProps as _TreeSelectProps,
  UploadProps as _UploadProps,
  ColProps,
  TabPaneProps as _TabPaneProps,
  TableProps,
} from 'ant-design-vue';
import { ValueEnum } from '../../types';
import { AxiosRequestConfig } from 'axios';
import type { IToolbarConfig } from '@wangeditor/editor';

export type RecordRow = Record<string, any>;

interface _ImageProps {
  request: (
    data: FormData,
    config?: AxiosRequestConfig,
  ) => Promise<{ data: { url: string } }>;
  maxCount?: number;
  accept?: string;
  size?: number;
  height?: number;
  width?: number;
}

export interface _EditorProps {
  toolbarKeys?: IToolbarConfig['toolbarKeys'];
  excludeKeys?: IToolbarConfig['excludeKeys'];
  uploadImage?: (file: File) => Promise<{
    url: string;
    alt?: string;
    href?: string;
    status?: boolean;
  }>;
}

interface BaseFieldProps {
  title: string;
  dataIndex: string;
  formItemProps?: FormItemProps;
  render?: (state: RecordRow) => any;
  formItemRender?: (state: RecordRow) => any;
  hidden?: (state: RecordRow) => boolean;
  colProps?: ColProps;
}

type FieldProps<T> = ((state: RecordRow) => T) | T;

interface InputProps extends BaseFieldProps {
  valueType: 'input';
  fieldProps?: FieldProps<_InputProps>;
}

interface InputNumberProps extends BaseFieldProps {
  valueType: 'inputNumber';
  fieldProps?: FieldProps<_InputNumberProps>;
}

interface PasswordProps extends BaseFieldProps {
  valueType: 'password';
  fieldProps?: FieldProps<_InputProps>;
}

interface TextareaProps extends BaseFieldProps {
  valueType: 'textarea';
  fieldProps?: FieldProps<_TextAreaProps>;
}

interface SelectProps extends BaseFieldProps {
  valueType: 'select';
  fieldProps?: FieldProps<_SelectProps>;
  valueEnum?: ValueEnum;
}

interface SwitchProps extends BaseFieldProps {
  valueType: 'switch';
  fieldProps?: FieldProps<_SwitchProps>;
}

interface CascaderProps extends BaseFieldProps {
  valueType: 'cascader';
  fieldProps?: FieldProps<_CascaderProps>;
}

interface CheckboxGroupProps extends BaseFieldProps {
  valueType: 'checkboxGroup';
  fieldProps?: FieldProps<_CheckboxGroupProps>;
}

interface CheckboxProps extends BaseFieldProps {
  valueType: 'checkbox';
  fieldProps?: FieldProps<_CheckboxProps>;
}

interface TreeSelectProps extends BaseFieldProps {
  valueType: 'treeSelect';
  fieldProps?: FieldProps<_TreeSelectProps>;
}

interface DatePickerProps extends BaseFieldProps {
  valueType: 'datePicker';
  fieldProps?: FieldProps<_DatePickerProps>;
}

interface DateRangeProps extends BaseFieldProps {
  valueType: 'dateRange';
  fieldProps?: FieldProps<_DatePickerProps>;
}

interface RadioProps extends BaseFieldProps {
  valueType: 'radio';
  fieldProps?: FieldProps<_RadioGroupProps>;
}

interface EditorProps extends BaseFieldProps {
  valueType: 'editor';
  fieldProps?: FieldProps<_EditorProps>;
}

interface ImageProps extends BaseFieldProps {
  valueType: 'image';
  fieldProps?: FieldProps<_ImageProps>;
}

export type ColumnChildren = {
  valueType: 'children';
  children: Column[];
};

export type Column =
  | InputProps
  | InputNumberProps
  | PasswordProps
  | TextareaProps
  | SelectProps
  | SwitchProps
  | CascaderProps
  | CheckboxGroupProps
  | CheckboxProps
  | TreeSelectProps
  | DatePickerProps
  | DateRangeProps
  | RadioProps
  | EditorProps
  | ImageProps;

export interface TabPaneProps {
  key: string;
  tab: string;
  columns: Column[];
}

export interface BoFormProps extends FormProps {
  rowProps?: _RowProps;
  colProps?: _ColProps;
  columns?: Column[];
  tabs?: TabPaneProps[];
}
